package org.example;

import java.util.HashMap;
import java.util.Map;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        String s = in.nextLine();
        char[] cA = in.nextLine().toCharArray();
        int zeroAmount = 0, oneAmount = 0;
        for(int i = 0; i < n; i++){
            if(cA[i] == '0') zeroAmount++;
            else oneAmount++;
        }

        if(zeroAmount % 2 != 0 || oneAmount % 2 != 0){
            System.out.println(0);
            return;
        }
        int left = 0, right = 0, num = 0;
        int zero = 0, z = zeroAmount / 2;
        int one = 0, o = oneAmount / 2;
        int window = n / 2;
        while(left <= n - 1){
            if(cA[right % n] == '0') zero++;
            else one++;
            while(right - left + 1 > window){
                if(cA[left] == '0') zero--;//
                else one--;
                left++;
            }
            if(zero == z && one == o) num++;
            right++;
        }
        System.out.println(num);
    }

    public static void main10(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        int n = in.nextInt();
        Set<String> set = new HashSet<>();
        while(n != 0){
            char[] c = in.nextLine().toCharArray();
            int[] arr = new int[128];
            for(int i = 0; i < c.length; i++){
                arr[c[i]]++;
            }
            String s = Arrays.toString(arr);
            set.add(s);
            n--;
        }
        System.out.println(set.size());
    }

    public static void main9(String[] args) {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt(), h = in.nextInt();
        int b = in.nextInt(), k = in.nextInt();
        long sum = 0;
        while(h != 0 && k != 0){
            sum += a + b;
            h -= b;
            k -= a;
        }
        if(h == 0 && k != 0) sum += (b * 10);
        else if(h != 0 && k == 0) sum += (a * 10);
        System.out.println(sum);
    }

    public static void main8(String[] args) {
        Scanner in = new Scanner(System.in);
        int t = in.nextInt();
        while(t != 0){
            t--;
            int n = in.nextInt();
            String S = in.nextLine();
            String[] s = new String[n];
            for(int i = 0; i < n; i++) s[i] = in.nextLine();
            int left = 0, right = n - 1;
            while(left < right){
                if(!istrue(s, left, right)){
                    break;
                }
                left++; right--;
            }
            if(left < right) System.out.println("No");
            else System.out.println("Yes");
        }
    }
    public static boolean istrue(String[] s, int left, int right){
        boolean[] b = new boolean[26];
        int len = s[right].length();
        for(int i = 0; i < len; i++) b[s[right].charAt(i) - 'a'] = true;
        len = s[left].length();
        for(int i = 0; i < len; i++){
            if(!b[s[left].charAt(i) - 'a']) return false;
        }
        return true;
    }


    public static void main6(String[] args) {
        Scanner in = new Scanner(System.in);
        char[] c = in.next().toCharArray();
        int len = c.length;
        for(int i = 0; i < len; i++){
            if((c[i] - '0') % 2 == 0){
                c[i] = '0';
            }else{
                c[i] = '1';
            }
        }
        int i = 0;
        while(i < len && c[i] == '0') i++;
        StringBuilder str = new StringBuilder();
        for(; i < len; i++) str.append(c[i]);
        if(str.length() == 0){
            System.out.println(0);
            return;
        }
        String s = str.toString();
        int num = Integer.parseInt(s);
        System.out.println(num);
    }

    public static void main5(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] arr = new int[10001];
        for(int i = 0; i < n; i++){
            int num = in.nextInt();
            arr[n]++;
        }
        long[] dp = new long[10001];
        if(arr[1] != 0) dp[1] = 1;
        for(int i = 2; i <= 10000; i++){
            if(arr[i] != 0){
                dp[i] = Math.max(dp[i - 1], dp[i - 2] + i);
            }else{
                dp[i] = Math.max(dp[i - 1], dp[i - 2]);
            }
        }
        System.out.println(dp[10000]);
    }

    public static void main4(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt() * 3;
        int[] arr = new int[n];
        for(int i = 0; i < n; i++) arr[i] = in.nextInt();
        Arrays.sort(arr);
        long sum = 0;
        for(int i = n - 2; i >= 0; i -= 2){
            sum += arr[i];
        }
        System.out.println(sum);
    }

    public static int maxLength (int[] arr) {
        int left = 0, right = 0, max = 0, len = arr.length;
        Map<Integer, Integer> hash = new HashMap<>();
        while(right < len){
            if(!hash.containsKey(arr[right]) || hash.get(arr[right]) == 0){
                hash.put(arr[right], 1);
                max = Math.max(max, right - left + 1);
                right++;
                continue;
            }
            hash.put(arr[right], 2);
            while(hash.get(arr[right]) == 1){
                int n = hash.get(arr[left]);
                hash.put(arr[left], n - 1);
                left++;
            }//
            right++;
        }
        int ret = 0;
        return ret;
    }

    public static void main3(String[] args) {
        int[] arr = {2,2,3,4,3};
        maxLength(arr);
    }

    public static void main2(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt(); String str = in.nextLine();
        char[] c = in.nextLine().toCharArray();
        int[] s = new int[n + 1];
        int[] sh = new int[n + 1];
        int[] shy = new int[n + 1];
        for(int i = 1; i <= n; i++){
            if(c[i - 1] == 's'){
                s[i] = s[i - 1] + 1;
                sh[i] = sh[i - 1];
                shy[i] = shy[i - 1];
            }else if(c[i - 1] == 'h'){
                s[i] = s[i - 1];
                sh[i] = sh[i - 1] + s[i];
                shy[i] = shy[i - 1];
            }else if(c[i - 1] == 'y'){
                s[i] = s[i - 1];
                sh[i] = sh[i - 1];
                shy[i] = shy[i - 1] + sh[i];
            }else{
                ;
            }
        }
        System.out.println(shy[n]);
    }

    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        char[] c = in.next().toCharArray();
        int len = c.length;
        for(int i = 0; i < len; i++){
            while(i < len && c[i] == ' '){
                i++;
            }
            if(i == len) break;
            int start = i,end = i + 1;
            while(end < len && c[end] != ' '){
                end++;
            }
            reverse(c, start, end);
            i = end;
        }
        reverse(c, 0, len);
        System.out.println(new String(c));
    }
    private static void reverse(char[] c, int start, int end){
        end--;
        while(start < end){
            char tmp = c[end];
            c[end] = c[start];
            c[start] = tmp;
            start++;
            end--;
        }
    }
}